import Vue from 'vue'
import Router from 'vue-router'
import publicRoute from '@/publicRoute/publicRoute'

Vue.use(Router)

let router= new Router({
  routes: [{
    path: '/',
    meta: {
      requireA: true,
      title:"首页",
      keepAlive: true
    },
    component: resolve => require(['@/components/page'], resolve)
  },
  ...publicRoute
  ]
})

/*
router.beforeEach((to,from,next)=>{
  let token = localStorage.getItem("token");
  if(to.meta.title){
    document.title ="vue多页系统-"+to.meta.title;
  }
  if(to.meta.rightRoute&&!token){
    if (!from.name && from.path === '/') {
      // 跳页面
      router.push({
        path: '/login',
        query: {
          redirectUrl: to.path
        }
      });
    } else {
      // 弹框登录
      let path = from.path + '?redirectUrl=' + to.path + '&dialog=' + Math.random();
      Object.keys(from.query).forEach(function (key) {
        if (path.indexOf(key + '=') === -1) {
          path += '&' + key + '=' + from.query[key];
        }
      });
      router.replace(path);
    }
  }else{
    next();
  }
})
*/
export default router
